/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Trp_sexoDAOImpl implements orm.dao.Trp_sexoDAO {
	public Trp_sexo loadTrp_sexoByORMID(String se_id_cod_sexo) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_sexoByORMID(session, se_id_cod_sexo);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo getTrp_sexoByORMID(String se_id_cod_sexo) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return getTrp_sexoByORMID(session, se_id_cod_sexo);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo loadTrp_sexoByORMID(String se_id_cod_sexo, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_sexoByORMID(session, se_id_cod_sexo, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo getTrp_sexoByORMID(String se_id_cod_sexo, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return getTrp_sexoByORMID(session, se_id_cod_sexo, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo loadTrp_sexoByORMID(PersistentSession session, String se_id_cod_sexo) throws PersistentException {
		try {
			return (Trp_sexo) session.load(orm.Trp_sexo.class, se_id_cod_sexo);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo getTrp_sexoByORMID(PersistentSession session, String se_id_cod_sexo) throws PersistentException {
		try {
			return (Trp_sexo) session.get(orm.Trp_sexo.class, se_id_cod_sexo);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo loadTrp_sexoByORMID(PersistentSession session, String se_id_cod_sexo, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Trp_sexo) session.load(orm.Trp_sexo.class, se_id_cod_sexo, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo getTrp_sexoByORMID(PersistentSession session, String se_id_cod_sexo, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Trp_sexo) session.get(orm.Trp_sexo.class, se_id_cod_sexo, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo[] listTrp_sexoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return listTrp_sexoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo[] listTrp_sexoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return listTrp_sexoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo[] listTrp_sexoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_sexo as Trp_sexo");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Trp_sexo[]) list.toArray(new Trp_sexo[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo[] listTrp_sexoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_sexo as Trp_sexo");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Trp_sexo[]) list.toArray(new Trp_sexo[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo loadTrp_sexoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_sexoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo loadTrp_sexoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_sexoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo loadTrp_sexoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Trp_sexo[] trp_sexos = listTrp_sexoByQuery(session, condition, orderBy);
		if (trp_sexos != null && trp_sexos.length > 0)
			return trp_sexos[0];
		else
			return null;
	}
	
	public Trp_sexo loadTrp_sexoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Trp_sexo[] trp_sexos = listTrp_sexoByQuery(session, condition, orderBy, lockMode);
		if (trp_sexos != null && trp_sexos.length > 0)
			return trp_sexos[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTrp_sexoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return iterateTrp_sexoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_sexoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return iterateTrp_sexoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_sexoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_sexo as Trp_sexo");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_sexoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_sexo as Trp_sexo");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo createTrp_sexo() {
		return new orm.Trp_sexo();
	}
	
	public boolean save(orm.Trp_sexo trp_sexo) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().saveObject(trp_sexo);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Trp_sexo trp_sexo) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().deleteObject(trp_sexo);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Trp_sexo trp_sexo)throws PersistentException {
		try {
			orm.Trp_alumno[] lTrp_alumnos = trp_sexo.trp_alumno.toArray();
			for(int i = 0; i < lTrp_alumnos.length; i++) {
				lTrp_alumnos[i].setSexo_id_cod(null);
			}
			return delete(trp_sexo);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Trp_sexo trp_sexo, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.Trp_alumno[] lTrp_alumnos = trp_sexo.trp_alumno.toArray();
			for(int i = 0; i < lTrp_alumnos.length; i++) {
				lTrp_alumnos[i].setSexo_id_cod(null);
			}
			try {
				session.delete(trp_sexo);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Trp_sexo trp_sexo) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().getSession().refresh(trp_sexo);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Trp_sexo trp_sexo) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().getSession().evict(trp_sexo);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_sexo loadTrp_sexoByCriteria(Trp_sexoCriteria trp_sexoCriteria) {
		Trp_sexo[] trp_sexos = listTrp_sexoByCriteria(trp_sexoCriteria);
		if(trp_sexos == null || trp_sexos.length == 0) {
			return null;
		}
		return trp_sexos[0];
	}
	
	public Trp_sexo[] listTrp_sexoByCriteria(Trp_sexoCriteria trp_sexoCriteria) {
		return trp_sexoCriteria.listTrp_sexo();
	}
}
